What is the First Come First Serve (FCFS) algorithm and why is it used in OS?
Explain the First Come First Serve (FCFS) algorithm with an example in OS.
1136
31-Mar-2023
Updated on 20-Apr-2023
Aryan Kumar
20-Apr-2023First Come First Serve (FCFS) is a scheduling algorithm in Operating System where the processes are executed in the order they arrive. The process that arrives first will be executed first and so on. It is a non-preemptive scheduling algorithm, which means that once a process starts executing, it will not be interrupted until it completes.
Here is an example of FCFS scheduling algorithm:
Consider there are three processes P1, P2, and P3 with their arrival times and burst times given below:
The Gantt chart for FCFS algorithm will be as follows:
The average waiting time and turnaround time for each process are as follows:
The Gantt chart shows the sequence in which the processes are executed. The waiting time for each process is the amount of time it spends waiting in the ready queue before it starts executing. The turnaround time for each process is the amount of time it takes to complete its execution from the time it arrives.
The average waiting time and turnaround time for all the processes are calculated by summing up the waiting time and turnaround time for each process and then dividing it by the number of processes.
FCFS is a simple and easy-to-understand scheduling algorithm. However, it is not suitable for systems with long-running processes or interactive systems where short response times are important. It also suffers from a problem called "convoy effect", where a long-running process can block the execution of short processes that arrive later.
Krishnapriya Rajeev
01-Apr-2023The First Come First Serve (FCFS) algorithm is a scheduling algorithm used by the operating system to allocate CPU time to processes. In this algorithm, the process that arrives first is assigned the CPU time first, and the process that arrives later is assigned the CPU time later. This algorithm is also known as the First-In-First-Out (FIFO) algorithm. It is non-preemptive.
Example:
Suppose there are three processes, P1, P2, and P3, that require CPU time to execute. The arrival time and burst time for each process are as follows:
The FCFS algorithm assigns the CPU time to the processes in the order they arrive. Therefore, the CPU time is first assigned to P1, then P2, and finally to P3. The Gantt chart for the execution of the processes using the FCFS algorithm is as follows:
As you can see from the Gantt chart, P1 is assigned the CPU time first and executes for 3 units of time. Then, P2 is assigned the CPU time and executes for 2 units of time. Finally, P3 is assigned the CPU time and executes for 1 unit of time. The total waiting time for P1, P2, and P3 is 0, 3, and 5, respectively.
The FCFS algorithm is simple to implement and easy to understand. However, it may not be the best choice for scheduling processes when the processes have widely varying burst times.